using UnityEngine;

public class ScriptableObjectSingleton<T> : ScriptableObject where T : ScriptableObject
{
	private static bool applicationIsQuitting;

	protected static T instance_;

	public static T instance
	{
		get
		{
			if (instance_ == null)
			{
				if (applicationIsQuitting)
				{
					return (T)null;
				}
				Debug.Log("Loading singleton from " + typeof(T).ToString());
				instance_ = Resources.Load<T>(typeof(T).ToString());
				(instance_ as ScriptableObjectSingleton<T>).Init();
			}
			return instance_;
		}
	}

	public void OnDestroy()
	{
		applicationIsQuitting = true;
	}

	protected virtual void Init()
	{
	}
}
